package cn.bone.chapter08;

/**
 * 标量替换测试（开启逃逸分析，关闭标量替换）
 * -Xmx100m -Xms100m -XX:+DoEscapeAnalysis -XX:+PrintGC -XX:-EliminateAllocations
 *
 * 开启逃逸分析，开启标量替换
 * -Xmx100m -Xms100m -XX:+DoEscapeAnalysis -XX:+PrintGC -XX:+EliminateAllocations
 */
public class ScalarReplace {

    public static class User {
        public int id;
        public String name;
    }

    public static void alloc(){
        User u = new User();
        u.id = 5;
        u.name = "www.superbone.com";
    }

    public static void main(String... args){
        long start = System.currentTimeMillis();
        for(int i=0; i<10000000; i++){
            alloc();
        }
        long end = System.currentTimeMillis();
        System.out.println("花费时间为：" + (end - start) + " ms");
    }
}
